.class Lcom/facebook/orca/protocol/ApiResponseWrapper;
.super Ljava/lang/Object;
.source "ApiResponseWrapper.java"


# instance fields
.field private final a:Lorg/json/JSONObject;

.field private final b:Lorg/json/JSONArray;


# direct methods
.method private constructor <init>(Ljava/lang/String;)V
    .locals 4
    .parameter

    .prologue
    const/4 v3, 0x0

    .line 25
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 26
    new-instance v0, Lorg/json/JSONTokener;

    invoke-direct {v0, p1}, Lorg/json/JSONTokener;-><init>(Ljava/lang/String;)V

    .line 27
    invoke-virtual {v0}, Lorg/json/JSONTokener;->nextClean()C

    move-result v1

    .line 28
    const/16 v2, 0x7b

    if-ne v1, v2, :cond_2

    .line 29
    invoke-virtual {v0}, Lorg/json/JSONTokener;->back()V

    .line 30
    new-instance v1, Lorg/json/JSONObject;

    invoke-direct {v1, v0}, Lorg/json/JSONObject;-><init>(Lorg/json/JSONTokener;)V

    iput-object v1, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    .line 31
    iput-object v3, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->b:Lorg/json/JSONArray;

    .line 32
    iget-object v0, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    const-string v1, "error_code"

    invoke-virtual {v0, v1}, Lorg/json/JSONObject;->has(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 34
    new-instance v0, Lcom/facebook/orca/server/ApiErrorResult;

    iget-object v1, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    const-string v2, "error_code"

    invoke-virtual {v1, v2}, Lorg/json/JSONObject;->getInt(Ljava/lang/String;)I

    move-result v1

    iget-object v2, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    const-string v3, "error_msg"

    invoke-virtual {v2, v3}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    invoke-static {v2}, Lcom/facebook/orca/common/util/JSONUtil;->a(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    invoke-direct {v0, v1, v2}, Lcom/facebook/orca/server/ApiErrorResult;-><init>(ILjava/lang/String;)V

    .line 37
    new-instance v1, Lcom/facebook/orca/server/ApiException;

    invoke-direct {v1, v0}, Lcom/facebook/orca/server/ApiException;-><init>(Lcom/facebook/orca/server/ApiErrorResult;)V

    throw v1

    .line 40
    :cond_0
    iget-object v0, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    const-string v1, "error"

    invoke-virtual {v0, v1}, Lorg/json/JSONObject;->has(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_1

    iget-object v0, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    const-string v1, "error"

    invoke-virtual {v0, v1}, Lorg/json/JSONObject;->get(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v0

    instance-of v0, v0, Ljava/lang/Integer;

    if-eqz v0, :cond_1

    .line 42
    new-instance v0, Lcom/facebook/orca/server/ApiErrorResult;

    iget-object v1, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    const-string v2, "error"

    invoke-virtual {v1, v2}, Lorg/json/JSONObject;->getInt(Ljava/lang/String;)I

    move-result v1

    iget-object v2, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    const-string v3, "error_description"

    invoke-virtual {v2, v3}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    invoke-static {v2}, Lcom/facebook/orca/common/util/JSONUtil;->a(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    invoke-direct {v0, v1, v2}, Lcom/facebook/orca/server/ApiErrorResult;-><init>(ILjava/lang/String;)V

    .line 45
    new-instance v1, Lcom/facebook/orca/server/ApiException;

    invoke-direct {v1, v0}, Lcom/facebook/orca/server/ApiException;-><init>(Lcom/facebook/orca/server/ApiErrorResult;)V

    throw v1

    .line 48
    :cond_1
    iget-object v0, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    const-string v1, "error"

    invoke-virtual {v0, v1}, Lorg/json/JSONObject;->has(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_3

    iget-object v0, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    const-string v1, "error"

    invoke-virtual {v0, v1}, Lorg/json/JSONObject;->get(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v0

    instance-of v0, v0, Lorg/json/JSONObject;

    if-eqz v0, :cond_3

    .line 49
    iget-object v0, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    const-string v1, "error"

    invoke-virtual {v0, v1}, Lorg/json/JSONObject;->getJSONObject(Ljava/lang/String;)Lorg/json/JSONObject;

    move-result-object v0

    .line 50
    new-instance v1, Lcom/facebook/orca/server/ApiErrorResult;

    const/4 v2, 0x0

    const-string v3, "message"

    invoke-virtual {v0, v3}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    invoke-static {v0}, Lcom/facebook/orca/common/util/JSONUtil;->a(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    invoke-direct {v1, v2, v0}, Lcom/facebook/orca/server/ApiErrorResult;-><init>(ILjava/lang/String;)V

    .line 53
    new-instance v0, Lcom/facebook/orca/server/ApiException;

    invoke-direct {v0, v1}, Lcom/facebook/orca/server/ApiException;-><init>(Lcom/facebook/orca/server/ApiErrorResult;)V

    throw v0

    .line 55
    :cond_2
    const/16 v2, 0x5b

    if-ne v1, v2, :cond_4

    .line 56
    invoke-virtual {v0}, Lorg/json/JSONTokener;->back()V

    .line 57
    new-instance v1, Lorg/json/JSONArray;

    invoke-direct {v1, v0}, Lorg/json/JSONArray;-><init>(Lorg/json/JSONTokener;)V

    iput-object v1, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->b:Lorg/json/JSONArray;

    .line 58
    iput-object v3, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    .line 62
    :cond_3
    return-void

    .line 60
    :cond_4
    new-instance v0, Lorg/json/JSONException;

    const-string v1, "Response was neither an array or a dictionary"

    invoke-direct {v0, v1}, Lorg/json/JSONException;-><init>(Ljava/lang/String;)V

    throw v0
.end method

.method public static a(Lcom/facebook/orca/protocol/ApiResponse;)Lcom/facebook/orca/protocol/ApiResponseWrapper;
    .locals 2
    .parameter

    .prologue
    .line 70
    new-instance v0, Lcom/facebook/orca/protocol/ApiResponseWrapper;

    invoke-virtual {p0}, Lcom/facebook/orca/protocol/ApiResponse;->a()Ljava/lang/String;

    move-result-object v1

    invoke-direct {v0, v1}, Lcom/facebook/orca/protocol/ApiResponseWrapper;-><init>(Ljava/lang/String;)V

    return-object v0
.end method

.method public static a(Ljava/lang/String;)Lcom/facebook/orca/protocol/ApiResponseWrapper;
    .locals 1
    .parameter

    .prologue
    .line 65
    new-instance v0, Lcom/facebook/orca/protocol/ApiResponseWrapper;

    invoke-direct {v0, p0}, Lcom/facebook/orca/protocol/ApiResponseWrapper;-><init>(Ljava/lang/String;)V

    return-object v0
.end method

.method public static b(Lcom/facebook/orca/protocol/ApiResponse;)V
    .locals 1
    .parameter

    .prologue
    .line 74
    invoke-virtual {p0}, Lcom/facebook/orca/protocol/ApiResponse;->a()Ljava/lang/String;

    move-result-object v0

    invoke-static {v0}, Lcom/facebook/orca/protocol/ApiResponseWrapper;->b(Ljava/lang/String;)V

    .line 75
    return-void
.end method

.method public static b(Ljava/lang/String;)V
    .locals 1
    .parameter

    .prologue
    .line 78
    invoke-static {p0}, Lcom/facebook/orca/common/util/StringUtil;->a(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 86
    :goto_0
    return-void

    .line 82
    :cond_0
    :try_start_0
    invoke-static {p0}, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a(Ljava/lang/String;)Lcom/facebook/orca/protocol/ApiResponseWrapper;
    :try_end_0
    .catch Lorg/json/JSONException; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 83
    :catch_0
    move-exception v0

    goto :goto_0
.end method


# virtual methods
.method public a()Lorg/json/JSONObject;
    .locals 2

    .prologue
    .line 89
    iget-object v0, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    if-nez v0, :cond_0

    .line 90
    new-instance v0, Lorg/json/JSONException;

    const-string v1, "Response was an array"

    invoke-direct {v0, v1}, Lorg/json/JSONException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 92
    :cond_0
    iget-object v0, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a:Lorg/json/JSONObject;

    return-object v0
.end method

.method public b()Lorg/json/JSONArray;
    .locals 2

    .prologue
    .line 96
    iget-object v0, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->b:Lorg/json/JSONArray;

    if-nez v0, :cond_0

    .line 97
    new-instance v0, Lorg/json/JSONException;

    const-string v1, "Response was a dictionary"

    invoke-direct {v0, v1}, Lorg/json/JSONException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 99
    :cond_0
    iget-object v0, p0, Lcom/facebook/orca/protocol/ApiResponseWrapper;->b:Lorg/json/JSONArray;

    return-object v0
.end method
